﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Landscape.WebApp.WCFServices;

namespace Landscape.WebApp.Controls
{
    public partial class JobDetails : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request.QueryString["VID"]))
                {
                    this.hfVesselID.Value = Request.QueryString["VID"].Trim();
                }

                if (!string.IsNullOrEmpty(Request.QueryString["SID"]))
                {
                    this.hfSystemID.Value = Request.QueryString["SID"].Trim();
                }

                if (!string.IsNullOrEmpty(Request.QueryString["JID"]))
                {
                    this.hfJobID.Value = Request.QueryString["JID"].Trim();
                }

                if (this.hfJobID.Value.Trim() != string.Empty)
                {
                    MaintenanceActions mActs = new MaintenanceActions();
                    var jobdet = mActs.GetJobByID(Guid.Parse(this.hfJobID.Value.Trim()));
                    this.rtbxJobCode.Text = jobdet.Code;
                    this.rtbxJobTitle.Text = jobdet.Title;
                    this.rtbxPeriodicity.Text = jobdet.Periodicity.ToString();
                    this.rtbxPriority.Text = jobdet.Priority;
                    this.rcbPeriodicityType.FindItemByText(jobdet.PeriodicityUnit).Selected = true;
                    this.reJobDescription.Content = jobdet.Description;

                    if (jobdet.IsReleased)
                    {
                        this.btnAdd.Visible = false;
                        this.btnClear.Visible = false;
                        this.lblErrorTxt.Text = "  The current job is released. You cannot save any updates.  ";
                    }
                    else
                    {
                        this.btnAdd.Text = "Save";
                        this.btnClear.Visible = false;

                    }
                }
                else
                {
                    this.lblErrorTxt.Visible = false;
                }

            }
        }
    }
}